package com.xintoucloud.springbootguide.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.xintoucloud.springbootguide.entity.Clazz;

import java.io.IOException;

/**
 * 自定义反序列化器
 */
public class ClazzJsonDeserializer extends JsonDeserializer<Clazz> {
    @Override
    public Clazz deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String cid = p.getValueAsString();
        Clazz clazz = new Clazz();
        clazz.setCid(Integer.valueOf(cid));
        return clazz;
    }
}
